/**
*      author: Y_Yao
*      created: 2024-11-26 16:53:59
**/

#include<bits/stdc++.h>
#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 20 + 5;
int a[N],p[N];
int adj[N][N];

void dfs(int x)
{
    if(p[x]) dfs(p[x]);
    cout << x << " ";
}

void solve()
{
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }

    for(int i = 1;i <= n - 1;i++)
    {
        for(int j = i + 1;j <= n;j++)
        {
            cin >> adj[i][j];
        }
    }

    vector<int> dp(N,0);
    int ans = 0;
    int pos = 0;
    for(int i = 1;i <= n;i++)
    {
        dp[i] = a[i];
        for(int j = i - 1;j > 0;j--)
        {
            if(adj[j][i] && dp[i] < dp[j] + a[i])
            {
                dp[i] = dp[j] + a[i];
                p[i] = j;
            }
        }
        if(dp[i] > ans)
        {
            ans = dp[i];
            pos = i;
        }
    }

    dfs(pos);
    cout << endl;
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}